package dao.impl;

import bean.Constant;

import java.io.*;


/**
 * @Author leiHua
 * @Date 2022/6/2 17:19
 */
public class FileDaoImpl {
    //更改 Athlete 首页 打开浏览器的url
    public void updateIndexUrl(String url) {
        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(new FileOutputStream(Constant.INDEX_URL));
            oos.writeObject(url);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException();
        } finally {
            try {
                if (oos != null)
                    oos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    //查询 Athlete 首页 打开浏览器的url
    public String selectIndexUrl(){
        ObjectInputStream ois=null;
        try {
            ois=new ObjectInputStream(new FileInputStream(Constant.INDEX_URL));
            String url =(String)ois.readObject();
            return url;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }finally {
            if (ois!=null){
                try {
                    ois.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }

    public static void main(String[] args) {
        FileDaoImpl fileDao = new FileDaoImpl();
        fileDao.updateIndexUrl("https://news.seig.edu.cn/cms/7610.html");
        System.out.println(fileDao.selectIndexUrl());
    }
}


